package org.streets.workflow.engine.condition;

import java.util.Map;

import org.apache.commons.jexl.Expression;
import org.apache.commons.jexl.ExpressionFactory;
import org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.JexlHelper;
import org.streets.workflow.engine.WorkflowContext;


/**
 * 缺省使用apache的JEXL实现条件表达式的解析。
 * 
 * 
 */
public class ConditionResolver implements IConditionResolver {
	protected WorkflowContext rtCtx = null;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.fireflow.kenel.condition.IConditionResolver#resolveBooleanExpression
	 * (java.lang.String)
	 */
	public boolean resolveBooleanExpression(String elExpression, Map<String ,Object> vars)
			throws Exception {
		Expression expression = ExpressionFactory.createExpression(elExpression);
		JexlContext jexlCtx = JexlHelper.createContext();
		jexlCtx.setVars(vars);
		Object obj = expression.evaluate(jexlCtx);
		return (Boolean) obj;
	}

	public void setRuntimeContext(WorkflowContext ctx) {
		rtCtx = ctx;
	}

	public WorkflowContext getRuntimeContext() {
		return this.rtCtx;
	}
}
